//
//  IndexedModel.h
//  Renderbunny
//
//  Created by Holmes Futrell on 1/21/11.
//  Copyright 2011 Holmes Futrell. All rights reserved.
//

#import "hashtable.h"
#import "platform.h"

// Attribute index.
enum {
    IMODEL_BUFFER_VERTEX,
    IMODEL_BUFFER_NORMAL,
	IMODEL_BUFFER_TANGENT,
	IMODEL_BUFFER_UV,
	IMODEL_BUFFER_ELEMENTS,
    IMODEL_NUM_BUFFERS
};

@interface IndexedModel : NSObject {

	struct hashtable  *hTable;

	int num_indices;
	int num_indexed_vertices;
	
	GLuint vao;
	
	GLushort *indices;
	GLuint buffers[IMODEL_NUM_BUFFERS];
	
	// buffer mappings initialized to -1
	// if a mapping does not exist buffer will not be used in drawing
	int attribMapping[IMODEL_NUM_BUFFERS];
	
}

// usage model
// 1.  initialize model
// 2.  map buffers
// 3.  create vertex array
// 4.  bind vertex array
// 5.  draw any number of times
// 6.  unbind vertex array

-(id)initWithFile:(NSString *)path;
-(void)mapBuffer:(int)buffer toAttributeLocation:(GLuint)location;
-(void)unmapBuffers;
-(void)createVertexArray;

-(void)bindVertexArray;
-(void)draw;
-(void)unbindVertexArray;

@end
